//
//  SixClassViewController.m
//  GSG
//
//  Created by dllo on 15/4/21.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "SixClassViewController.h"
#import"SixCollectionViewCell.h"
#import"AFNetworking.h"
#import"AFNetworkingTool.h"
#import"UIImageView+WebCache.h"
#import"SongListViewController.h"
#import"PlayListViewController.h"
#import"MBProgressHUD.h"
@interface SixClassViewController ()

@property(nonatomic,retain)NSMutableArray *arr;
@property(nonatomic,retain)NSMutableArray *songlistArr;//用来装小分类的数组 例如:起床等
@property(nonatomic,retain)UICollectionView*myCollectionView;
@property(nonatomic,retain)MBProgressHUD *HUD;
@end

@implementation SixClassViewController
- (void)dealloc
{
    [_arr release];
    [_songlistArr release];
    [_myCollectionView release];
    [_HUD release];
    [super dealloc];
}
-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    
    if (self) {
        _arr=[[NSMutableArray alloc]init];
        _songlistArr=[[NSMutableArray alloc]init];
    }
    [self analysisData];
    return  self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
     self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"播放" style:UIBarButtonItemStyleDone target:self action:@selector(actionBuLand)];
     self.navigationItem.rightBarButtonItem.tintColor=[UIColor whiteColor];
    //标题
    UILabel *titleLable=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width * 170 / 375, self.view.frame.size.height * 30 / 667, self.view.frame.size.width * 50 / 375, self.view.frame.size.height * 30 / 667)];
    [self.view addSubview:titleLable];
    titleLable.text=self.strTitle;
    [titleLable release];
    
    //内容
    UICollectionViewFlowLayout *myFlowLayout=[[UICollectionViewFlowLayout alloc]init];
    myFlowLayout.itemSize=CGSizeMake(self.view.frame.size.width * 100 / 375, self.view.frame.size.height * 120 / 667);
    myFlowLayout.minimumLineSpacing=10;
    myFlowLayout.minimumInteritemSpacing=10;
    myFlowLayout.scrollDirection=0;
    myFlowLayout.sectionInset=UIEdgeInsetsMake(self.view.frame.size.width * 20 / 375, self.view.frame.size.height * 20 / 667, self.view.frame.size.width * 20 / 375, self.view.frame.size.height * 20 / 667);
    
    self.myCollectionView=[[UICollectionView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height * 60 / 667, self.view.frame.size.width, self.view.frame.size.height)  collectionViewLayout:myFlowLayout];

    self.myCollectionView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"ef.png"]];

    self.myCollectionView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bujing.png"]];

    [self.view addSubview:self.myCollectionView];
    self.myCollectionView.delegate=self;
    self.myCollectionView.dataSource=self;
    [self.myCollectionView registerClass:[SixCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];

//小菊花
    //方式1.直接在View上show
    _HUD = [[MBProgressHUD showHUDAddedTo:self.view animated:YES] retain];
    
    
    //常用的设置
    //小矩形的背景色
    _HUD.color = [UIColor clearColor];//这儿表示无背景
    //显示的文字
    _HUD.labelText = @"提示";
    //细节文字
    _HUD.detailsLabelText = @"正在加载内容";
    //是否有庶罩
    _HUD.dimBackground = YES;

}

-(void)analysisData
{
    NSString*str=@"http://fm.api.ttpod.com/channellist?image_type=240_200&app=ttpod&v=v7.7.0.2015012818&uid=&mid=iPhone5S&f=f320&s=s310&imsi=&hid=&splus=7.1&active=1&net=2&openudid=f6194442ca8980c5d85b989cf3d3dc0a4377fda1&idfa=5AA671CE-591C-4ED9-9D2B-A3E90383B9F1&utdid=VTDTxsGQAW8DAMDeSyjEEAeS&alf=201200";
    [AFNetworkingTool NetWorkingTooStr:str block:^(id result) {
        self.arr=[result objectForKey:@"data"];
        if ([self.strTitle isEqualToString: @"场景"]) {
            NSDictionary *dic15=[self.arr objectAtIndex:15];
            NSDictionary *dic16=[self.arr objectAtIndex:16];
            NSDictionary *dic17=[self.arr objectAtIndex:17];
            NSDictionary *dic18=[self.arr objectAtIndex:18];
            NSDictionary *dic19=[self.arr objectAtIndex:19];
            NSDictionary *dic20=[self.arr objectAtIndex:20];
            NSDictionary *dic21=[self.arr objectAtIndex:21];
            NSDictionary *dic22=[self.arr objectAtIndex:22];
            NSDictionary *dic23=[self.arr objectAtIndex:23];
            NSDictionary *dic24=[self.arr objectAtIndex:24];
            NSDictionary *dic25=[self.arr objectAtIndex:25];
            self.songlistArr=[NSMutableArray arrayWithObjects:dic15,dic16,dic17,dic18,dic19,dic20,dic21,dic22,dic23,dic24,dic25, nil];
        }
        if([self.strTitle isEqualToString:@"心情"]){
            NSDictionary *dic43=[self.arr objectAtIndex:43];
            NSDictionary *dic33=[self.arr objectAtIndex:33];
            NSDictionary *dic34=[self.arr objectAtIndex:34];
            NSDictionary *dic35=[self.arr objectAtIndex:35];
            NSDictionary *dic36=[self.arr objectAtIndex:36];
            NSDictionary *dic37=[self.arr objectAtIndex:37];
            NSDictionary *dic38=[self.arr objectAtIndex:38];
            NSDictionary *dic39=[self.arr objectAtIndex:39];
            NSDictionary *dic40=[self.arr objectAtIndex:40];
            NSDictionary *dic41=[self.arr objectAtIndex:41];
            NSDictionary *dic42=[self.arr objectAtIndex:42];
            self.songlistArr=[NSMutableArray arrayWithObjects:dic33 ,dic34,dic35,dic36,dic37,dic38,dic39,dic40,dic41,dic42,dic43, nil];
        }
        if([self.strTitle isEqualToString:@"语言"]){
            NSDictionary *dic26=[self.arr objectAtIndex:26];
            NSDictionary *dic27=[self.arr objectAtIndex:27];
            NSDictionary *dic28=[self.arr objectAtIndex:28];
            NSDictionary *dic29=[self.arr objectAtIndex:29];
            NSDictionary *dic30=[self.arr objectAtIndex:30];
            NSDictionary *dic31=[self.arr objectAtIndex:31];
            NSDictionary *dic32=[self.arr objectAtIndex:32];
            self.songlistArr=[NSMutableArray arrayWithObjects:dic26,dic27,dic28,dic29,dic30,dic31,dic32 ,nil];
        }
        if ([self.strTitle isEqualToString:@"风格"]) {
            NSDictionary *dic44=[self.arr objectAtIndex:44];
            NSDictionary *dic45=[self.arr objectAtIndex:45];
            NSDictionary *dic46=[self.arr objectAtIndex:46];
            NSDictionary *dic47=[self.arr objectAtIndex:47];
            NSDictionary *dic48=[self.arr objectAtIndex:48];
            NSDictionary *dic49=[self.arr objectAtIndex:49];
            NSDictionary *dic50=[self.arr objectAtIndex:50];
            NSDictionary *dic51=[self.arr objectAtIndex:51];
            NSDictionary *dic52=[self.arr objectAtIndex:52];
            NSDictionary *dic53=[self.arr objectAtIndex:53];
            NSDictionary *dic54=[self.arr objectAtIndex:54];
            NSDictionary *dic55=[self.arr objectAtIndex:55];
            self.songlistArr=[NSMutableArray arrayWithObjects:dic44,dic45,dic46,dic47,dic48,dic49,dic50,dic51,dic52,dic53,dic54 ,dic55, nil];
        }
        if ([self.strTitle isEqualToString:@"特色"]) {
            NSDictionary *dic56=[self.arr objectAtIndex:56];
            NSDictionary *dic57=[self.arr objectAtIndex:57];
            NSDictionary *dic58=[self.arr objectAtIndex:58];
            NSDictionary *dic59=[self.arr objectAtIndex:59];
            NSDictionary *dic60=[self.arr objectAtIndex:60];
            NSDictionary *dic61=[self.arr objectAtIndex:61];
            NSDictionary *dic62=[self.arr objectAtIndex:62];
            NSDictionary *dic63=[self.arr objectAtIndex:63];
            NSDictionary *dic64=[self.arr objectAtIndex:64];
            NSDictionary *dic65=[self.arr objectAtIndex:65];
            NSDictionary *dic66=[self.arr objectAtIndex:66];
            NSDictionary *dic67=[self.arr objectAtIndex:67];
            self.songlistArr=[NSMutableArray arrayWithObjects:dic56,dic57,dic58,dic59,dic60,dic61,dic62,dic63,dic64,dic65,dic66,dic67,nil];
        }
        if ([self.strTitle isEqualToString:@"年代"]) {
            NSDictionary *dic69=[self.arr objectAtIndex:69];
            NSDictionary *dic70=[self.arr objectAtIndex:70];
            NSDictionary *dic71=[self.arr objectAtIndex:71];
            self.songlistArr=[NSMutableArray arrayWithObjects:dic69,dic70,dic71,nil];
        }
        [self.myCollectionView reloadData ];
        [_HUD hide:YES ];
    }];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.songlistArr.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    SixCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    cell. sortLabel.text=[self.songlistArr[indexPath.row] objectForKey:@"songlist_name"];
    NSURL *url=[NSURL URLWithString:[self.songlistArr[indexPath.row] objectForKey:@"large_pic_url"]];
    [cell.sortImageView sd_setImageWithURL:url];
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    SongListViewController*sslvc=[[SongListViewController alloc]init];
    sslvc.dic=self.songlistArr[indexPath.row];
    [self.navigationController pushViewController:sslvc animated:YES];
    [sslvc release];
}
-(void)actionBuLand{
    PlayListViewController *plvc=[[PlayListViewController alloc]init];
    [self.navigationController pushViewController:plvc animated:YES];
    [plvc release];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
